package com.knight.dynamicproxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

public class DynamicProxyClient {
    //-Dsun.misc.ProxyGenerator.saveGeneratedFiles=true 配置JVM参数保存动态代理对象的字节码
    public static void main(String[] args) {
        RealSubject realSubject = new RealSubject();

        InvocationHandler invocationHandler = new DynamicSubject(realSubject);
        Class<?> clazz = invocationHandler.getClass();
        // 创建代理对象
        Subject proxyInstance = (Subject)Proxy.newProxyInstance(clazz.getClassLoader(), realSubject.getClass().getInterfaces(),
                invocationHandler);

        proxyInstance.request();
        System.out.println(proxyInstance.getClass());
    }
}
